<template>
    <div id="register">
      <p class="iconfont icon-cuowu"></p>
      <h2>手机号注册</h2>
      <div class="inputbox">
        <input type="text" placeholder="手机号/用户名" v-model="value.name" />
        <input type="password" placeholder="密码" v-model="value.pass" />
        <input type="password" placeholder="确认密码" v-model="value.opass" />
        <button @click="sendaxios">注册</button>
      </div>
      <p @click="gologin">已有账号去登录</p>
    </div>
  </template>
    
    <script>

  export default {
    data() {
      return {
        value: { name: "", pass: "", opass: "" },
      };
    },
    methods: {
      // 发请求
      sendaxios() {
        if (this.value.name && this.value.pass && this.value.opass) {
          if (this.value.pass == this.value.opass) {
            register({ phone: this.value.name, pass: this.value.pass }).then(
              (res) => {
                // 注册成功
                if (res.data.status == "ok") {
                  alert("注册成功");
                  //   跳到登录页
                  this.$router.replace({path:'/lu'})
                }
              }
            );
          }
          else{
              alert('密码不一致')
          }
        } else {
          alert("账号/密码不能为空");
        }
      },
      gologin(){
        this.$router.push('/lu')
      }
    },
  };
  </script>
    
    <style scoped>
  .icon-cuowu {
    color: black;
    font-size: 30px;
  }
  h2 {
    margin-top: 80px;
    margin-left: 5%;
  }
  .inputbox {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
  }
  .inputbox input {
    width: 90%;
    border: none;
    border-bottom: 1px solid gray;
    height: 35px;
    outline: none;
    box-sizing: border-box;
    color: gray;
    margin-top: 10px;
  }
  .inputbox button {
    width: 90%;
    height: 30px;
    line-height: 30px;
    outline: none;
    color: gray;
    background-color: rgb(215, 215, 215);
    border: none;
    border-radius: 15px;
    margin-top: 60px;
  }
  p {
    display: flex;
    justify-content: space-between;
    color: blue;
    margin-top: 10px;
    box-sizing: border-box;
    padding: 0 5%;
  }
  </style>
    